{extend name="public:base" /}
{block name="style"}
<style>
    .h30{
        height: 30px;
        line-height: 30px;
    }
</style>
{/block}
{block name="main-content"}
<div class="page-content">

    <div class="row">
        <div class="col-xs-12">
            <!-- 提示 -->
            <div class="row h30">
                <div class="col-xs-5">
                    <a href="{:url('admin/article/set')}"><span class="glyphicon glyphicon-plus addArticle" >创建</span></a>&nbsp;&nbsp;
                    <a href="javascript:void(0);"><span class="glyphicon glyphicon-question-sign">帮助</span></a>
                </div>
                <div class="col-xs-7">

                </div>
            </div>

            <div class="row">
                <div class="col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered" id="ListTable">
                            <thead>
                            <tr>
                                <th class="center">
                                    <label class="pos-rel">
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </th>
                                <th>编号</th>
                                <th>文章标题</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>更新时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {empty name="list"}
                            <tr>
                                <td colspan="7">暂时没有数据</td>
                            </tr>

                            {else/}

                            {volist name="list" id="vo"}
                            <tr>
                                <td class="center">
                                    <label class="pos-rel">
                                        <input type="checkbox" class="ace" name="id[]" value="{$vo.id}">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{$vo.id}</td>
                                <td>{$vo.subject}</td>
                                <td>{$vo.status}</td>
                                <td>{$vo.created_time}</td>
                                <td>{$vo.updated_time}</td>
                                <td>
                                    <a href="{:url('admin/article/set','id='.$vo.id)}" class="editArticle">编辑</a>
                                    <a href="javascript:void(0);">删除</a>
                                </td>
                            </tr>
                            {/volist}
                            <tr>
                                <td colspan="7" class="row">
                                    <div class="col-xs-2">
                                        <select class="form-control" id="positionId" name="positionId">
                                            <option value="0">--请选择推荐位--</option>
                                            {foreach  name="position" id="vo"}
                                            <option value="{$vo.id}">{$vo.name}</option>
                                            {/foreach}
                                        </select>

                                    </div>
                                    <div class="col-xs-10">
                                        <button type="button" class="btn btn-primary btn-sm" id="setPositionBtn" data-url="{:url('admin/article/push')}">推送</button>
                                        <button type="button" class="btn btn-primary btn-sm" id="baiduPush" data-url="{:url('admin/article/baiduPush')}">百度推送</button>
                                    </div>

                                </td>
                            </tr>
                            {if condition='$page'}
                            <tr>
                                <td colspan="7">{$page}</td>
                            </tr>
                            {/if}
                            {/empty}
                            </tbody>
                        </table>
                    </div>
                </div>

            </div>

            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div><!-- /.page-content -->
{/block}

{block name="scripts"}
<script type="text/javascript">
$(document).ready(function () {
    //设置推荐位
    $("#setPositionBtn").on('click', function () {
        var positionId = parseInt($("#positionId").val());
        var ids = [];
        $("input[name^='id']:checked").each(function (i) {
            ids[i] = parseInt($(this).val());
        });

        if (!positionId) {
            layer.alert('请选择推荐位', {icon: 5});
            return false;
        }
        if (!ids.length) {
            layer.alert('请选择要设置推送的文章', {icon: 5});
            return false;
        }

        var url = $(this).data('url');
        var idStr = '';
        if (ids.length > 0) {
            idStr = ids.join(',');
        }

        $.post(url,{'ids':idStr, 'positionId':positionId}, function (data) {
            console.log(data);
            if (data.code) {
                layer.alert(data.msg, {icon: 6});
            } else {
                layer.alert(data.msg, {icon: 5});
            }
        }, 'json');
    });

    //百度推送
    $("#baiduPush").on('click', function () {
        var ids = [];
        $("input[name^='id']:checked").each(function (i) {
            ids[i] = parseInt($(this).val());
        });

        if (!ids.length) {
            layer.alert('请选择要设置推送到百度的文章', {icon: 5});
            return false;
        }

        var url = $(this).data('url');
        var idStr = '';
        if (ids.length > 0) {
            idStr = ids.join(',');
        }

        $.post(url,{'ids':idStr}, function (data) {
            console.log(data);
            if (data.code) {
                layer.alert(data.msg, {icon: 6});
            } else {
                layer.alert(data.msg, {icon: 5});
            }
        }, 'json');
    });
});
</script>
{/block}